package com.github.admin.edu.oauth.server.interceptor;

import com.github.admin.edu.assembly.exception.auth.ClientTokenException;
import com.github.admin.edu.assembly.string.util.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Create by IntelliJ IDEA
 * 用户：王建
 * 日期：2018-7-19
 */
public class ClientAuthInterceptor extends HandlerInterceptorAdapter {

    /**
     * 自定义头 名称
     */
    @Value("${server.custom.token.header}")
    private String tokenHeader;

    @Value("${server.custom.token.client-id}")
    private String clientId;

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        String token=request.getHeader(tokenHeader);
        String client_Id=request.getHeader(clientId);
        if(StringUtils.isNotBlank(token)&&StringUtils.isNotBlank(client_Id)){

            return true;
        }
        throw  new ClientTokenException("token is not find !!!!!! ");
    }
}
